package com.xyebank.ledger.service.jryzadd.adaper;

import com.xyebank.ledger.db.entitys.LApplicationInf;
import com.xyebank.ledger.service.common.conveter.ApplyBeanConverter;
import com.xyebank.ledger.service.constant.CommonConstant;
import com.xyebank.ledger.service.constant.ProductConstant;
import com.xyebank.ledger.util.DateConverter;
import com.xyebank.ledger.util.DateUtil;
import com.xyebank.ledger.util.IDUtil;
import com.xyebank.ledger.vo.deal.ZADDJryCashApplyVo;

import org.modelmapper.AbstractConverter;
import org.modelmapper.Converter;
import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component(value = "zaddJryApplyBeanConverter")
public class ZAADJryApplyBeanConverter implements ApplyBeanConverter<ZADDJryCashApplyVo> {

	ModelMapper modelMapper = new ModelMapper();


	// 不能采取注入方式
	private DateConverter dateConverter = new DateConverter();

	class NXApplyPropertyMap extends PropertyMap<ZADDJryCashApplyVo, LApplicationInf> {
		// 注意 不要有重复的映射，不然会报错
		protected void configure() {
			// 订单号
			map(source.getSsjloanno(), destination.getXyOrderNo());
			// 电话号码
			map(source.getMblNO(), destination.getMblNo());
			// 状态
			// map(source.getStatus(), destination.getStatus());
			// 授信金额（可用金额）
			map(source.getLimitavail(), destination.getCreditAmount());
			// 申请时间
			map(source.getCreTime(), destination.getApplyTime());
		}
	}

	public ZAADJryApplyBeanConverter() {
		modelMapper.addMappings(new NXApplyPropertyMap());
	}

	@Override
	public LApplicationInf covert(ZADDJryCashApplyVo x) {
		LApplicationInf entity = modelMapper.map(x, LApplicationInf.class);
		entity.setDataSource(CommonConstant.JRY_STR);
		entity.setXyOrgNo(ProductConstant.ZADD_LOAN_ORG);
		entity.setXyProductNo(ProductConstant.ZADD_PROD_ID);
		entity.setId(IDUtil.generateId(x.getd(), "zadd_jry_apply"));
		String status = x.getStatus();
		if (status.equals("0")) {
			entity.setStatus(CommonConstant.APPLY_SUCCESS);
		} else if (status.equals("1")) {
			entity.setStatus(CommonConstant.APPLY_ING);
		} else if (status.equals("2") || status.equals("4")) {
			entity.setStatus(CommonConstant.APPLY_FAIL);
		} else if (status.equals("3")) {
			entity.setStatus(CommonConstant.APPLY_OVER);
		}

		return entity;
	}
}
